﻿using System.Linq;
using NHibernate;
using AprenderComendo.Models;
using NHibernate.Linq;
using System.Collections.Generic;

namespace AprenderComendo.Infrastructure.Persistence
{
    public class PresentationRepository : AbstractRepository, IPresentationRepository
    {
        public PresentationRepository(ISession session)
            : base(session)
        {
        }

        public System.Collections.Generic.IList<Models.Presentation> FindAll()
        {
            return (from presentations in Session.Linq<Presentation>() 
                    select presentations).ToList<Presentation>();
        }


        public IList<Presentation> FindBy(string searchstring)
        {
            return
                (from presentation in Session.Linq<Presentation>() 
                 where presentation.Title == searchstring || presentation.Authors.Any(x => x.Name == searchstring) 
                 select presentation).ToList();
        }


        public void Save(Presentation presentation)
        {
            Session.Save(presentation);
        }
    }
}